package com.night.common.entity;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author rzh6230
 * 2022/8/27 15:19
 * ResultVo<?>
 *
 * ### code
 *
 * | 状态码 | 英文        | 描述           |
 * | ------ | ----------- | -------------- |
 * | 200    | OK          | 成功返回       |
 * | 400    | FAIL        | 失败           |
 * | 500    | ERROR       | 服务器出错     |
 * | 700    | NOPERM      | 权限不足       |
 * | 701    | NOSESSION   | 会话失效       |
 * | 401    | ACCOUNTFAIL | 账户和密码错误 |
 * | 402    | CAPTCHAFAIL | 验证码错误     |
 * | 403    | TOKENFAIL   | 令牌失效       |
 * | 404    | OTHERLOGIN  | 异地登录       |
 * | 800    | VALUEFAIL   | 参数错误       |
 *
 * ## msg
 *
 * ## data(T)
 */
@Data
public class ResultVo<T>{
    private int code;
    private String msg;
    private T data;

    /**
     * @Author CHX42
     * @Description 200返回，无数据带回
     * @Date  2022/8/28  12:00
     * @Param
     * @return
     **/
    public static final ResultVo<String> SUCCESS= new ResultVo<>(StatusCode.OK.code, StatusCode.OK.msg);
    /**
     * @Author CHX42
     * @Description 服务器出错
     * @Date  2022/8/28  12:00
     * @Param
     * @return
     **/
    public static final ResultVo<String> ERROR= new ResultVo<>(StatusCode.ERROR.code, StatusCode.ERROR.msg);

    /**
     * @Author CHX42
     * @Description 400返回
     * @Date  2022/8/28  12:02
     * @Param
     * @return
     **/
    public static final ResultVo<String> FAIL= new ResultVo<>(StatusCode.FAIL.code, StatusCode.FAIL.msg);

    public static final ResultVo<String> ACCOUNT_FAIL= new ResultVo<>(StatusCode.ACCOUNT_FAIL.code, StatusCode.ACCOUNT_FAIL.msg);

    public ResultVo() {
    }

    public ResultVo(int code, String msg) {
        this(code, msg, null);
    }

    public ResultVo(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * @Author CHX42
     * @Description 200返回，有数据带回
     * @Date  2022/8/28  12:03
     * @Param [data]
     * @return
     **/
    public ResultVo(T data) {
        this.code = StatusCode.OK.code;
        this.msg = StatusCode.OK.msg;
        this.data = data;
    }

    /**
     * @Author CHX42
     * @Description 使用枚举创建，有数据返回的相应结构
     * @Date  2022/8/28  11:56
     * @Param [statusCode：枚举【com.wnnight.wys.entity.StatusCode】; data：返回相应的数据，格式不限]
     * @return
     **/
    public ResultVo(StatusCode statusCode, T data){
        this.code=statusCode.code;
        this.msg=statusCode.msg;
        this.data=data;
    }

    /**
     * @Author CHX42
     * @Description 使用枚举创建，无数据返回的相应结构
     * @Date  2022/8/28  11:59
     * @Param [statusCode]
     * @return
     **/
    public ResultVo(StatusCode statusCode){
        this.code=statusCode.code;
        this.msg=statusCode.msg;
    }
}
